﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UtilZ.Dotnet.Ex.Communication.Net.Web
{
    /// <summary>
    /// http头项
    /// </summary>
    public class HeaderItem
    {
        /// <summary>
        /// 头名称
        /// </summary>
        public string Name { get; private set; }

        /// <summary>
        /// 值
        /// </summary>
        public string Value { get; private set; }

        /// <summary>
        /// 项字符串
        /// </summary>
        public string Header { get; private set; }

        /// <summary>
        /// 项类型[true:name-value;false:项字符串]
        /// </summary>
        public bool ItemType { get; private set; }


        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="name">头名称</param>
        /// <param name="value">值</param>
        public HeaderItem(string name, string value)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            this.Name = name;
            this.Value = value;
            this.ItemType = true;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="header">项字符串</param>
        public HeaderItem(string header)
        {
            this.Header = header;
            this.ItemType = false;
        }



        /// <summary>
        /// 重写ToString
        /// </summary>
        /// <returns>String</returns>
        public override string ToString()
        {
            if (this.ItemType)
            {
                return this.Header;
            }

            return $"{this.Name}:{this.Value}";
        }
    }
}
